import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { resolve } from 'path'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // 按需导入
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    }),
    // SvgIcon图标
    createSvgIconsPlugin({
      iconDirs: [resolve(__dirname, './src/assets/svg')],
      symbolId: 'icon-[dir]-[name]'
    })
  ],
  // 配置路径别名
  resolve: {
    alias: {
      '@': resolve(__dirname, './src')
    }
  },
  base: './',
  // 请求地址跨域
  server: {
    https: false,
    hotOnly: false,
    port: 8090,
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:8001',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '') //重写路径,替换/api
      }
    }
  },
  // 全局样式
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `
        @import "@/styles/variables.scss";
        @import "@/styles/mixin.scss";
        `
      }
    }
  }
})
